﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "AddPlatformPages.h"
#include "IUiDocumentViewManager.h"
#include "IMainWindow.h"
#include "GbmpUiPlatformCommandIds.h"
#include "GcmpCommandNames.h"
#include "CommandBase.h"
#include "IPublishConfig.h"
#include "IRibbon.h"
#include "IRibbonQuickAccessBar.h"
#include "ICommandButtonDefinition.h"
#include "GmGbmpUiConfigurationCommandRegister.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

class QuickAccessBarCmd : public CommandBase
{
public:
    QuickAccessBarCmd() : CommandBase(GetMyCommandString()) {}
    virtual ~QuickAccessBarCmd() {}
    static const std::wstring& GetMyCommandString()
    {
        static std::wstring commandString = ID_QUICKACCESS_BAR;
        return commandString;
    }

    // ICommand实现
public:
    virtual bool IsEnabled() const override
    {
        DBG_WARN(L"Ribbon Page没有Enable的属性",L"GDMPLab",L"2024-03-30");
        return true;
    }

    virtual bool IsVisible() const override
    {
        return IUiDocumentViewManager::Get()->GetAllUiDocuments().empty() == false;
    }
};


REGISTER_GM_COMMAND(QuickAccessBarCmd);

void AddPlatformPages::AddQuickAccessBar()
{
    IRibbon* pRibbon = IMainWindow::GetMainWindow()->GetRibbon();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pRibbon, L"pRibbon为空",L"GDMPLab",L"2024-03-30");

    IRibbonQuickAccessBar* pQuickAccessBar = pRibbon->GetLeftQuickAccessBar();
    DBG_WARN_AND_RETURN_VOID_UNLESS(pQuickAccessBar, L"pQuickAccessBar为空",L"GDMPLab",L"2024-03-30");
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_NEW_FILE, GBMP_TR(L"新建"), GBMP_TR(L"新建"), ID_CMD_NEW_FILE, L":/images/quickAccess/新建.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_OPEN_FILE, GBMP_TR(L"打开"), GBMP_TR(L"打开"), ID_CMD_OPEN_FILE, L":/images/quickAccess/打开.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_SAVE_FILE, GBMP_TR(L"保存"), GBMP_TR(L"保存"), ID_CMD_SAVE_FILE, L":/images/quickAccess/保存.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_SAVE_FILE_AS, GBMP_TR(L"另存为"), GBMP_TR(L"另存为"), ID_CMD_SAVE_FILE_AS, L":/images/quickAccess/另存为.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_CLOSE_FILE, GBMP_TR(L"关闭"), GBMP_TR(L"关闭"), ID_CMD_CLOSE_FILE, L":/images/quickAccess/关闭.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_UNDO, GBMP_TR(L"撤消"), GBMP_TR(L"撤消(Ctrl+Z)"), ID_CMD_UNDO, L":/images/quickAccess/撤消.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
    {
        OwnerPtr<ICommandButtonDefinition> opButtonDef = ICommandButtonDefinition::Create(ID_CMD_REDO, GBMP_TR(L"重做"), GBMP_TR(L"重做(Ctrl+Y)"), ID_CMD_REDO, L":/images/quickAccess/重做.png");
        pQuickAccessBar->AddButton(TransferOwnership(opButtonDef));
    }
}
